package Alex.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class AddMoviePage extends InternalPage {

	public AddMoviePage(PageManager pages) {
		super(pages);
	}
	
  public AddMoviePage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.cssSelector("#imdbsearchform")));
    return this;
  }
  
  @FindBy(css = "input[class='required error']")
  private WebElement titleField;

  @FindBy(css = "textarea[name='aka']")
  private WebElement akaField;
  
  @FindBy(css = "input[class='required digits error']")
  private WebElement yearField;

  @FindBy(css = "input[name='duration']")
  private WebElement durationField;
  
  @FindBy(css = ".number")
  private WebElement ratingField;
  
  @FindBy(css = "#submit")
  private WebElement saveButton;
  
  
  public AddMoviePage setTitle (String text){
	  titleField.sendKeys(text);
	  return this;
  }
 
  public AddMoviePage setAkaField (String text){
	  akaField.sendKeys(text);
	  return this;
  }
  
  public AddMoviePage setYear (String text){
	  yearField.sendKeys(text);
	  return this;
  }
  
  public AddMoviePage setDuration (String text){
	  durationField.sendKeys(text);
	  return this;
  }
  
  public AddMoviePage setRating (String text){
	  ratingField.sendKeys(text);
	  return this;
  }

  public EditMoviePage clickSaveButton() {
	    saveButton.click();
	    return pages.editMoviePage;
  }


  
}